home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / if_cscop.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  15.5 KB  |  404 lines

  1. *if_cscop.txt*  For Vim version 6.0.  Last change: 2001 Sep 05
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Andy Kahn
  5.  
  6.                             *cscope* *Cscope*
  7. This document explains how to use Vim's cscope interface.
  8.  
  9. Cscope is a tool like ctags, but think of it as ctags on steroids since it
  10. does a lot more than what ctags provides.  In Vim, jumping to a result from
  11. a cscope query is just like jumping to any tag; it is saved on the tag stack
  12. so that with the right keyboard mappings, you can jump back and forth between
  13. functions as you normally would with |tags|.
  14.  
  15. 1. Cscope introduction        |cscope-intro|
  16. 2. Cscope related commands    |cscope-commands|
  17. 3. Cscope options        |cscope-options|
  18. 4. How to use cscope in Vim    |cscope-howtouse|
  19. 5. Limitations            |cscope-limitations|
  20. 6. Suggested usage        |cscope-suggestions|
  21. 7. Availability & Information    |cscope-info|
  22.  
  23. This is currently for Unix only.
  24. {Vi does not have any of these commands}
  25.  
  26. ==============================================================================
  27. 1. Cscope introduction                    *cscope-intro*
  28.  
  29. The following text is taken from a version of the cscope man page:
  30.  
  31.                     -----
  32.  
  33.   Cscope is an interactive screen-oriented tool that helps you:
  34.  
  35.        Learn how a C program works without endless flipping through a thick
  36.        listing.
  37.  
  38.        Locate the section of code to change to fix a bug without having to
  39.        learn the entire program.
  40.  
  41.        Examine the effect of a proposed change such as adding a value to an
  42.        enum variable.
  43.  
  44.        Verify that a change has been made in all source files such as adding
  45.        an argument to an existing function.
  46.  
  47.        Rename a global variable in all source files.
  48.  
  49.        Change a constant to a preprocessor symbol in selected lines of files.
  50.  
  51.   It is designed to answer questions like:
  52.        Where is this symbol used?
  53.        Where is it defined?
  54.        Where did this variable get its value?
  55.        What is this global symbol's definition?
  56.        Where is this function in the source files?
  57.        What functions call this function?
  58.        What functions are called by this function?
  59.        Where does the message "out of space" come from?
  60.        Where is this source file in the directory structure?
  61.        What files include this header file?
  62.  
  63.   Cscope answers these questions from a symbol database that it builds the
  64.   first time it is used on the source files.  On a subsequent call, cscope
  65.   rebuilds the database only if a source file has changed or the list of
  66.   source files is different.  When the database is rebuilt the data for the
  67.   unchanged files is copied from the old database, which makes rebuilding
  68.   much faster than the initial build.
  69.  
  70.                     -----
  71.  
  72. When cscope is normally invoked, you will get a full-screen selection
  73. screen allowing you to make a query for one of the above questions.
  74. However, once a match is found to your query and you have entered your
  75. text editor to edit the source file containing match, you cannot simply
  76. jump from tag to tag as you normally would with vi's Ctrl-] or :tag
  77. command.
  78.  
  79. Vim's cscope interface is done by invoking cscope with its line-oriented
  80. interface, and then parsing the output returned from a query.  The end
  81. result is that cscope query results become just like regular tags, so
  82. you can jump to them just like you do with normal tags (Ctrl-] or :tag)
  83. and then go back by popping off the tagstack with Ctrl-T.  (Please note
  84. however, that you don't actually jump to a cscope tag simply by doing
  85. Ctrl-] or :tag without remapping these commands or setting an option.
  86. See the remaining sections on how the cscope interface works and for
  87. suggested use.)
  88.  
  89.  
  90. ==============================================================================
  91. 2. Cscope related commands                *cscope-commands*
  92.  
  93.         *:cscope* *:cs* *:scs* *:scscope* *E259* *E262*
  94. All cscope commands are accessed through suboptions to the main cscope
  95. command ":cscope".  The shortest abbreviation is ":cs".  The ":scscope"
  96. command does the same and also splits the window (short: "scs").
  97.  
  98. The available subcommands are:
  99.  
  100.     add   : Add a new cscope database/connection.
  101.  
  102.     USAGE    :cs add {file|dir} [pre-path] [flags]
  103.  
  104.         [pre-path] is the pathname used with the -P command to cscope.
  105.  
  106.         [flags] are any additional flags you want to pass to cscope.
  107.  
  108.     EXAMPLES >
  109.         :cscope add /usr/local/cdb/cscope.out
  110.         :cscope add /projects/vim/cscope.out /usr/local/vim
  111.         :cscope add cscope.out /usr/local/vim -C
  112. <
  113.     find  : Query cscope.  All cscope query options are available
  114.         except option #5 ("Change this grep pattern").
  115.  
  116.     USAGE    :cs find {querytype} {name}
  117.  
  118.         {querytype} corresponds to the actual cscope line
  119.         interface numbers as well as default nvi commands:
  120.  
  121.         0 or s: Find this C symbol
  122.         1 or g: Find this definition
  123.         2 or d: Find functions called by this function
  124.         3 or c: Find functions calling this function
  125.         4 or t: Find assignments to
  126.         6 or e: Find this egrep pattern
  127.         7 or f: Find this file
  128.         8 or i: Find files #including this file
  129.  
  130.     EXAMPLES >
  131.         :cscope find c vim_free
  132.         :cscope find 3 vim_free
  133. <
  134.         These two examples perform the same query. >
  135.  
  136.         :cscope find 0 DEFAULT_TERM
  137. <
  138.         Executing this example on the source code for Vim 5.1 produces the
  139.         following output:
  140.  
  141.         Cscope tag: DEFAULT_TERM
  142.            #   line  filename / context / line
  143.            1   1009  vim-5.1-gtk/src/term.c <<GLOBAL>>
  144.              #define DEFAULT_TERM (char_u *)"amiga"
  145.            2   1013  vim-5.1-gtk/src/term.c <<GLOBAL>>
  146.              #define DEFAULT_TERM (char_u *)"win32"
  147.            3   1017  vim-5.1-gtk/src/term.c <<GLOBAL>>
  148.              #define DEFAULT_TERM (char_u *)"pcterm"
  149.            4   1021  vim-5.1-gtk/src/term.c <<GLOBAL>>
  150.              #define DEFAULT_TERM (char_u *)"ansi"
  151.            5   1025  vim-5.1-gtk/src/term.c <<GLOBAL>>
  152.              #define DEFAULT_TERM (char_u *)"vt52"
  153.            6   1029  vim-5.1-gtk/src/term.c <<GLOBAL>>
  154.              #define DEFAULT_TERM (char_u *)"os2ansi"
  155.            7   1033  vim-5.1-gtk/src/term.c <<GLOBAL>>
  156.              #define DEFAULT_TERM (char_u *)"ansi"
  157.            8   1037  vim-5.1-gtk/src/term.c <<GLOBAL>>
  158.              # undef DEFAULT_TERM
  159.            9   1038  vim-5.1-gtk/src/term.c <<GLOBAL>>
  160.              #define DEFAULT_TERM (char_u *)"beos-ansi"
  161.           10   1042  vim-5.1-gtk/src/term.c <<GLOBAL>>
  162.              #define DEFAULT_TERM (char_u *)"mac-ansi"
  163.           11   1335  vim-5.1-gtk/src/term.c <<set_termname>>
  164.              term = DEFAULT_TERM;
  165.           12   1459  vim-5.1-gtk/src/term.c <<set_termname>>
  166.              if (STRCMP(term, DEFAULT_TERM))
  167.           13   1826  vim-5.1-gtk/src/term.c <<termcapinit>>
  168.              term = DEFAULT_TERM;
  169.           14   1833  vim-5.1-gtk/src/term.c <<termcapinit>>
  170.              term = DEFAULT_TERM;
  171.           15   3635  vim-5.1-gtk/src/term.c <<update_tcap>>
  172.              p = find_builtin_term(DEFAULT_TERM);
  173.         Enter nr of choice (<CR> to abort):
  174.  
  175.         The output shows several pieces of information:
  176.         1. The tag number (there are 15 in this example).
  177.         2. The line number where the tag occurs.
  178.         3. The filename where the tag occurs.
  179.         4. The context of the tag (e.g., global, or the function name).
  180.         5. The line from the file itself.
  181.  
  182.     help  : Show a brief synopsis.
  183.  
  184.         USAGE   :cs help
  185.  
  186.                         *E260* *E261*
  187.     kill  : Kill a cscope connection (or kill all cscope connections).
  188.  
  189.         USAGE   :cs kill {num|partial_name}
  190.  
  191.         To kill a cscope connection, the connection number or a partial
  192.         name must be specified.  The partial name is simply any part of
  193.         the pathname of the cscope database.  Kill a cscope connection
  194.         using the partial name with caution!
  195.  
  196.         If the specified connection number is -1, then _ALL_ cscope
  197.         connections will be killed.
  198.  
  199.     reset : Reinit all cscope connections.
  200.  
  201.         USAGE   :cs reset
  202.  
  203.     show  : Show cscope connections.
  204.  
  205.         USAGE   :cs show
  206.  
  207.                             *:cstag* *E257*
  208. If you use cscope as well as ctags, |:cstag| allows you to search one or
  209. the other before making a jump.  For example, you can choose to first
  210. search your cscope database(s) for a match, and if one is not found, then
  211. your tags file(s) will be searched.  The order in which this happens
  212. is determined by the value of |csto|.  See |cscope-options| for more
  213. details.
  214.  
  215. |:cstag| performs the equivalent of ":cs find g" on the identifier when
  216. searching through the cscope database(s).
  217.  
  218. |:cstag| performs the equivalent of |:tjump| on the identifier when searching
  219. through your tags file(s).
  220.  
  221.  
  222. ==============================================================================
  223. 3. Cscope options                    *cscope-options*
  224.  
  225. Use the |:set| command to set all cscope options.  Ideally, you would do
  226. this in one of your startup files (e.g., .vimrc).  Some cscope related
  227. variables are only valid within |.vimrc|.  Setting them after vim has
  228. started will have no effect!
  229.  
  230.                             *cscopeprg* *csprg*
  231. 'cscopeprg' specifies the command to execute cscope.  The default is
  232. "cscope".  For example: >
  233.     :set csprg=/usr/local/bin/cscope
  234. <
  235.                             *cscopetag* *cst*
  236. If 'cscopetag' set, the commands ":tag" and CTRL-] as well as "vim -t" will
  237. always use |:cstag| instead of the default :tag behavior.  Effectively, by
  238. setting 'cst', you will always search your cscope databases as well as your
  239. tag files.  The default is off.  Examples: >
  240.     :set cst
  241.     :set nocst
  242. <
  243.                             *cscopetagorder* *csto*
  244. The value of 'csto' determines the order in which |:cstag| performs a search.
  245. If 'csto' is set to zero, cscope database(s) are searched first, followed
  246. by tag file(s) if cscope did not return any matches.  If 'csto' is set to
  247. one, tag file(s) are searched before cscope database(s).  The default is zero.
  248. Examples: >
  249.     :set csto=0
  250.     :set csto=1
  251. <
  252.                         *cscopeverbose* *csverb*
  253. If 'cscopeverbose' is not set (the default), messages will not be printed
  254. indicating success or failure when adding a cscope database.  Ideally, you
  255. should reset this option in your |.vimrc| before adding any cscope databases,
  256. and after adding them, set it.  From then on, when you add more databases
  257. within Vim, you will get a (hopefully) useful message should the database fail
  258. to be added.  Examples: >
  259.     :set csverb
  260.     :set nocsverb
  261. <
  262.                               *cscopepathcomp* *cspc*
  263. The value of 'cspc' determines how many components of a file's path to
  264. display.  With the default value of zero the entire path will be displayed.
  265. The value one will display only the filename with no path.  Other values
  266. display that many components.  For example: >
  267.     :set cspc=3
  268. will display the last 3 components of the file's path, including the file
  269. name itself.
  270.  
  271. ==============================================================================
  272. 4. How to use cscope in Vim                *cscope-howtouse*
  273.  
  274. The first thing you need to do is to build a cscope database for your
  275. source files.  For the most basic case, simply do "cscope -b".  Please
  276. refer to the cscope man page for more details.
  277.  
  278. Assuming you have a cscope database, you need to "add" the database to Vim.
  279. This establishes a cscope "connection" and makes it available for Vim to use.
  280. You can do this in your .vimrc file, or you can do it manually after starting
  281. vim.  For example, to add the cscope database "cscope.out", you would do:
  282.  
  283.     :cs add cscope.out
  284.  
  285. You can double-check the result of this by executing ":cs show".  This will
  286. produce output which looks like this:
  287.  
  288.  # pid      database name                  prepend path
  289.  0 28806  cscope.out                  <none>
  290.  
  291. Once a cscope connection is established, you can make queries to cscope and
  292. the results will be printed to you.  Queries are made using the command
  293. ":cs find".  For example:
  294.  
  295.     :cs find g ALIGN_SIZE
  296.  
  297. This can get a little cumbersome since one ends up doing a significant
  298. amount of typing.  Fortunately, there are ways around this by mapping
  299. shortcut keys.  See |cscope-suggestions| for suggested usage.
  300.  
  301. If the results return only one match, you will automatically be taken to it.
  302. If there is more than one match, you will be given a selection screen to pick
  303. the match you want to go to.  After you have jumped to the new location,
  304. simply hit Ctrl-T to get back to the previous one.
  305.  
  306.  
  307. ==============================================================================
  308. 5. Limitations                        *cscope-limitations*
  309.  
  310. Cscope support for Vim is only available on systems that support these four
  311. system calls: fork(), pipe(), execl(), waitpid().  This means it is mostly
  312. limited to Unix systems.
  313.  
  314. Libraries are available for Win95 (win32) which translate a lot of Unix
  315. system calls to the Win32 API.  You can try the GNU-Win32 Project from Cygnus
  316. (http://www.cygnus.com/misc/gnu-win32) or the DJGPP suite of tools
  317. (http://www.delorie.com/djgpp/).  I do not know the status of using these with
  318. Vim, so they may or may not work.
  319.  
  320. Additionally, there are a couple of hard-coded limitations:
  321.  
  322.     1. The maximum number of cscope connections allowed is 8.  Do you
  323.     really need more?
  324.  
  325.     2. Doing a |:tjump| when |:cstag| searches the tag files is not
  326.     configurable (e.g., you can't do a tselect instead).
  327.  
  328. ==============================================================================
  329. 6. Suggested usage                    *cscope-suggestions*
  330.  
  331. Put these entries in your .vimrc (adjust the pathname accordingly to your
  332. setup): >
  333.  
  334.     if has("cscope")
  335.         set csprg=/usr/local/bin/cscope
  336.         set csto=0
  337.         set cst
  338.         set nocsverb
  339.         " add any database in current directory
  340.         if filereadable("cscope.out")
  341.             cs add cscope.out
  342.         " else add database pointed to by environment
  343.         elseif $CSCOPE_DB != ""
  344.             cs add $CSCOPE_DB
  345.         endif
  346.         set csverb
  347.     endif
  348.  
  349. By setting 'cscopetag', we have effectively replaced all instances of the :tag
  350. command with :cstag.  This includes :tag, Ctrl-], and "vim -t".  In doing
  351. this, the regular tag command not only searches your ctags generated tag
  352. files, but your cscope databases as well.
  353.  
  354. Some users may want to keep the regular tag behavior and have a different
  355. shortcut to access :cstag.  For example, one could map Ctrl-_  (underscore)
  356. to :cstag with the following command: >
  357.  
  358.     map <C-_> :cstag <C-R>=expand("<cword>")<CR><CR>
  359.  
  360. A couple of very commonly used cscope queries (using ":cs find") is to
  361. find all functions calling a certain function and to find all occurrences
  362. of a particular C symbol.  To do this, you can use these mappings as an
  363. example: >
  364.  
  365.     map g<C-]> :cs find 3 <C-R>=expand("<cword>")<CR><CR>
  366.     map g<C-\> :cs find 0 <C-R>=expand("<cword>")<CR><CR>
  367.  
  368. These mappings for Ctrl-] (right bracket) and Ctrl-\ (backslash) allow you to
  369. place your cursor over the function name or C symbol and quickly query cscope
  370. for any matches.
  371.  
  372. ==============================================================================
  373. 7. Cscope availability and information            *cscope-info*
  374.  
  375. If you do not already have cscope (it did not come with your compiler
  376. license or OS distribution), then you can download it for free from:
  377.     http://cscope.sourceforge.net/
  378. This is released by SCO under the BSD license.
  379.  
  380. If you want a newer version of cscope, you will probably have to buy it.
  381. According to the nvi documentation:
  382.  
  383.     You can buy version 13.3 source with an unrestricted license
  384.     for $400 from AT&T Software Solutions by calling +1-800-462-8146.
  385.  
  386. In Solaris 2.x, if you have the C compiler license, you will also have
  387. cscope.  Both are usually located under /opt/SUNWspro/bin
  388.  
  389. SGI developers can also get it.  Currently a tardist file can be found at:
  390.     ftp://ftp.openage.com/pub/Sgi/Binaries/Cscope-13_3_tardist.gz
  391.     https://toolbox.sgi.com/toolbox/utilities/cscope/
  392. The second one is for those who have a password for the SGI toolbox.
  393.  
  394. There is source to an older version of a cscope clone (called "cs") available
  395. on the net.  Due to various reasons, this is not supported with Vim.
  396.  
  397. The cscope interface/support for Vim was originally written by
  398. Andy Kahn <ackahn@netapp.com>.  The original structure (as well as a tiny
  399. bit of code) was adapted from the cscope interface in nvi.  Please report
  400. any problems, suggestions, patches, et al., you have for the usage of
  401. cscope within Vim to him.
  402.  
  403.  vim:tw=78:ts=8:ft=help:norl:
  404.